package com.liyunc.demo.service;

import com.liyunc.demo.model.entity.Department;
import com.liyunc.demo.model.repository.DepartmentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class DepartmentService {
    @Autowired
    private DepartmentRepository departmentRepository;

    public void saveDepartment(Department department) {
        departmentRepository.save(department);
    }

    public Department findDepartmentByName(String name) {
        return departmentRepository.findDepartmentByName(name);
    }

    @Transactional
    public void deleteDepartmentById(Long id) {
        departmentRepository.deleteById(id);
    }
}
